﻿using UnityEngine;
using System.Collections;

public class paddleController : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.position = new Vector3(Camera.main.ScreenToWorldPoint (Input.mousePosition).x, transform.position.y, transform.position.z) ; 
	 	transform.position = new Vector3(Mathf.Clamp( transform.position.x, -14, 14), transform.position.y, transform.position.z);
	}
	
	void OnCollisionEnter(Collision collision) 
	{ 
		var velo = collision.rigidbody.velocity.magnitude; 
		collision.rigidbody.velocity = new Vector3((collision.transform.position.x - transform.position.x)*8, collision.rigidbody.velocity.y, collision.rigidbody.velocity.z); 
		if (collision.rigidbody.velocity.magnitude < velo) 
		{
			collision.rigidbody.velocity *= velo/collision.rigidbody.velocity.magnitude; 
		}
	}
}

